package menu_api

import (
	"benkendSystem/database"
	"benkendSystem/models"
	"github.com/gin-gonic/gin"
	"net/http"
)

// DeleteMenu 删除菜单
func DeleteMenu(c *gin.Context) {
	in := new(DeleteMenuRequest)
	err := c.ShouldBindJSON(in)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "参数错误",
		})
		return
	}
	err = database.DB.Model(new(models.Menu)).Where("id = ?", in.ID).Updates(map[string]any{
		"deleted_flag": true,
	}).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "操作失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "操作成功",
	})
}
